package hu.crs.demobank.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class AccountNumberFormatter implements Converter{

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value)
			throws ConverterException {
		String valueString= (String) value;
		String strippedString=valueString.replace("-", "");
		return strippedString;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object value)
			throws ConverterException {
		// TODO Auto-generated method stub
		String valueString= (String) value;
		String formattedAccountNumber = valueString.substring(0, 7)+"-"+valueString.substring(8, 15)+"-"+valueString.substring(16, 23);
		return formattedAccountNumber;
	}

}
